<?php
defined('BASEPATH') OR exit('No direct script access allowed');
/**
 * Created by PhpStorm.
 * The project “dev”
 * File name “index.php”
 *
 * User: znx
 * Company: 思议创想
 * Q  Q: 865303386
 * Site: www.siyi360.com
 *
 * Date: 2017-02-08
 * Time: 17:20
 */

class Index extends CI_Controller {
    public function __construct()
    {
        parent::__construct();

        $this->load->library('Tree');
        $this->load->model('index/Login_model');
        $this->load->model('index/Main_model');
    }

    /**
     * login
     * 系统用户登录页面
     */
    public function login()
    {
        $this->load->view('index/login');
    }

    /**
     * login_action
     * 系统用户登录请求
     */
    public function login_action()
    {
        if (!IS_POST) exit();

        $return = $this->Login_model->login();
        exit(json_encode($return));
    }

    /**
     * logout
     * 系统用户退出登录
     *
     */
    public function logout()
    {
        $return = $this->Login_model->user_logout();
        exit(json_encode($return));
    }

    /**
     * main
     * 管理系统主框架（main）
     *
     * @param int $user_id 当前登录系统用户的用户信息
     */
    public function main()
    {
        // 登录检测
        if (!$this->admin_auth->check_user_login()) redirect(site_url('../login'));

        //获取系统菜单
        $query = $this->Main_model->get_menu(1);
        $data['menu'] = Tree::makeTree($query, array(
            'primary_key' => 'menu_id',
            'parent_key' => 'menu_parentid',
        ));

        $this->load->view('index/index', $data);
    }

    /**
     * home
     * 系统主页
     *
     */
    public function home()
    {
        $this->load->view('index/home');
    }

    /**
     * user_safe
     * 更新当前登录的系统用户信息
     *
     * @param int $user_id 系统用户id
     */
    public function user_safe($user_id)
    {
        if (!IS_POST) exit();

        $result = $this->Main_model->user_safe($user_id);

        exit(json_encode($result));
    }

    /*
    * 测试使用
    * */
    public function test()
    {
        //$s = $this->session->user_acl;
        //var_dump($s);
        // echo $this->router->fetch_class();
        // echo $this->router->fetch_method();
        /*$menu = $this->Main_model->get_menu();
        $menu_list = Tree::makeTree($menu, array(
            'primary_key' => 'menu_id',
            'parent_key' => 'menu_parentid',
        ));

        print_r($menu_list);*/

        /*$captch = new \Minho\Captcha\CaptchaBuilder();

        $captch->initialize([
            'width' => 150,     // 宽度
            'height' => 44,     // 高度
            'line' => false,    // 直线
            'curve' => true,    // 曲线
            'noise' => 1,       // 噪点背景
            'fonts' => []       // 字体
        ]);
        $captch->create();

        $captch->output(1);*/

        // $_SESSION['verify_code'] = $captch->getText();
        /*$test = '{
    "banner_big": [
        "/uploads/goods/banner/1487736235.jpg",
        "/uploads/goods/banner/1487736239.jpg",
        "/uploads/goods/banner/1487736244.jpg"
    ],
    "album_big": [
        "/uploads/goods/album/1487736270.png",
        "/uploads/goods/album/1487736296.png"
    ]
}';
        $arr = json_decode($test, true);
        //($arr['banner_big']);

        foreach ($arr['banner_big'] as $val) {
            echo $val.'<hr>';
        }*/
    }
}